#include "packagemanager.hpp"

namespace PackageManager
{
	void login(QStringList args, QSslSocket* client,QMap<QSslSocket*,int>* connectedClients)
	{
		Database database;
		int id = database.login(args[0], args[1]);
		if (id == -1) // If wrong pass
		{
			client->write("login:0");
		}
		else if (connectedClients->key(id) != NULL) // If client already connected
		{
			client->write("login:-1");
		}
		else
		{
			connectedClients->insert(client,id);
			client->write("login:1");
		}
	}


	// Args[0] = fileName
	void ecg(QStringList args, QSslSocket* client)
	{
		qDebug() << args[0];
		QFile ecgFile(QString("../ressources/"+args[0]));
		ecgFile.open(QIODevice::Text | QIODevice::ReadOnly);

		while(!ecgFile.atEnd())
			client->write("ecg:"+ecgFile.readLine());
	}
}




